//
//  WYBusinessController.m
//  Boss
//
//  Created by admin on 2018/6/1.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYBusinessController.h"
#import "SDCycleScrollView.h"
#import "WYSectionView.h"
#import "WYBrandCell.h"
#import "WYCategoryCell.h"
#import "WYCategoryTableViewCell.h"
#import "WYHotIndustryCell.h"
#import "WYBusinessRecommendCell.h"
#import "WYBrandController.h"
#import "WYFoodController.h"
#import "NSString+Extension.h"
#import "WYBusinessModule.h"
#import "WYSlideshow.h"
#import "WYBrandZone.h"
#import "WYBusinessOpportunity.h"
#import "WYBusinessDetailController.h"
#import "WYBusinessType.h"
#import "WYHotIndustryViewCell.h"
#import "WYHotSector.h"
#import "WYLoginController.h"
#import "WYBaseNavigationController.h"
#import "WYStrictSeletedTableViewCell.h"
#import "CJTopLineOneCell.h"
#import "CJTopLineThreeCell.h"
#import "CJTopLineBigCell.h"
#import "CJBOSSRecommendCell.h"
#import "CJFourBusiness.h"
#import "CJBusinessTypeController.h"
#import "CJBOSSHeadLine.h"
#import "CJBrandJoinController.h"
#import "CJChannelController.h"
#import "CJBOSSPersonController.h"
#import "CJTopLineController.h"
#import "WYSlideshow.h"
#import "WYBusinessSearchController.h"
#import "CJBOSSChannel.h"
#import "CJBOSSRecommend.h"
#import <PYSearch/PYSearch.h>
#import "CJCommissionController.h"
#import "CJTopLineDetailController.h"
#import "CJBrandDetailController.h"
#import "CJBrandAdvertising.h"
@interface WYBusinessController ()<UITableViewDelegate,UITableViewDataSource,WYSectionViewDelegate,WYCategoryCellDelegate,WYCategoryTableViewCellDelegate,SDCycleScrollViewDelegate,WYBrandCellDelegate,WYHotIndustryViewCellDelegate,UITextFieldDelegate,PYSearchViewControllerDelegate,CJBOSSRecommendCellDelegate>
@property (nonatomic, strong) SDCycleScrollView *advView;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong) WYBusinessModule *businessModel;

@property (nonatomic,strong) NSMutableArray *fourArray;
@property (nonatomic,strong) NSMutableArray *headLineArray;
@property (nonatomic,strong) UITextField *textField;
@property (nonatomic,strong) UIView *titleView;
@property (nonatomic,strong)NSMutableArray *channelArray;
@property (nonatomic,strong) NSMutableArray *recommendArray;
@property (nonatomic,strong) NSMutableArray *adverArray;
@property (nonatomic)NSUInteger page;
@property (nonatomic)BOOL isRefresh;
@property (nonatomic,strong)NSArray *bannerArray;
@end

@implementation WYBusinessController
-(NSMutableArray *)adverArray
{
    if (!_adverArray) {
        _adverArray = [[NSMutableArray alloc]init];
    }
    return _adverArray;
}
-(NSMutableArray *)recommendArray
{
    if (!_recommendArray) {
        _recommendArray = [[NSMutableArray alloc]init];
    }
    return _recommendArray;
}




-(NSMutableArray *)channelArray
{
    if (!_channelArray) {
        _channelArray = [[NSMutableArray alloc]init];
    }
    return _channelArray;
}
-(NSMutableArray *)headLineArray
{
    if (!_headLineArray) {
        _headLineArray = [[NSMutableArray alloc]init];
    }
    return _headLineArray;
}
-(NSMutableArray *)fourArray
{
    if (!_fourArray) {
        _fourArray = [[NSMutableArray alloc]init];
    }
    
    return _fourArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isRefresh = YES;
    [self setupUI];
   // [self loadData];
    [self loadFourType];
    [self loadBossLine];
    [self loadBanner];
    [self loadBOSSChannel];
    [self loadRecommend];
    [self loadAdvertising];
    [self wr_setNavBarBackgroundAlpha:0];
    
    WEAKSELF
    self.tableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        weakSelf.isRefresh=NO;
        weakSelf.page++;
        [weakSelf loadRecommend];
    }];
}

-(void)loadAdvertising
{
    WEAKSELF
    [WYHttpServer getMerchantAdvertisingSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            [weakSelf.adverArray addObjectsFromArray:[CJBrandAdvertising getAdvertisingModelFromJson:response[@"result"]]];
            [weakSelf.tableView reloadData];
        }
        
        
        
        
    }];
    
    
    
}



-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.isRefresh = YES;
    [self loadRecommend];
    
}
-(void)loadRecommend
{
    WEAKSELF
    [WYHttpServer getBOSSRecommendCurrentPage:@"1" WithPageSize:@"20" SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            if (weakSelf.isRefresh) {
                [weakSelf.recommendArray removeAllObjects];
            }
            
            
            [weakSelf.recommendArray addObjectsFromArray:[CJBOSSRecommend getRemmendModelFromJson:response[@"result"][@"detail"]]];
            [weakSelf.tableView reloadData];
            if ([response[@"result"][@"hasNextPage"] integerValue]) {
                [weakSelf.tableView.mj_footer endRefreshing];
            }else{
                [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
        
    }];
    
    
}

-(void)loadBOSSChannel
{
    WEAKSELF
    [WYHttpServer getBOSSChannelSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            
            [weakSelf.channelArray addObjectsFromArray:[CJBOSSChannel getChannelModelFromJson:response[@"result"]]];
            
        }
        
        
    }];
    
}

-(void)loadBanner
{
    WEAKSELF
    [WYHttpServer getSlideShowSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        
        if (success) {
            NSArray *bannerArray = [WYSlideshow getSlideShowFromJson:response[@"result"]];
            
            NSMutableArray *imageArray=[[NSMutableArray alloc]init];
            weakSelf.bannerArray = bannerArray;
            if (bannerArray.count) {
                for (WYSlideshow *slidesShow in bannerArray) {
                    NSString *imageUrl = [NSString stringWithFormat:@"%@!default",slidesShow.url];
                    [imageArray addObject:imageUrl];
                }
                
                
            }
            [self.advView setImageURLStringsGroup:imageArray];
            
            
        }
        
        
        
    }];
    
    
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//    WYBusinessSearchController *bsc = [[WYBusinessSearchController alloc]init];
//    [self.navigationController pushViewController:bsc animated:YES];
    
    PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[@"餐饮",@"招商",@"创业",@"加盟",@"渠道"] searchBarPlaceholder:@"搜索品牌、产品、人脉、资讯" didSearchBlock:^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
        // Called when search begain.
        // eg：Push to a temp view controller
//        WYBusinessSearchController *src = [[WYBusinessSearchController alloc]init];
//        src.searchTitle = searchText;
//        [searchViewController.navigationController pushViewController:src animated:YES];
    }];
    searchViewController.hotSearchStyle = PYHotSearchStyleDefault;
    searchViewController.searchHistoryStyle = PYSearchHistoryStyleNormalTag;
    searchViewController.delegate = self;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
    [self presentViewController:nav animated:YES completion:nil];
    //searchViewController.navigationItem.hidesBackButton = YES;
   // [self.navigationController pushViewController:searchViewController animated:YES];
    
    
    
    return NO;
    
}

-(void)loadBossLine
{
    WEAKSELF
    [WYHttpServer getBossLineSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [weakSelf.headLineArray addObjectsFromArray:[CJBOSSHeadLine getHeadLineFromJson:response[@"result"]]];
            [weakSelf.tableView reloadData];
        }
    }];
}
-(void)loadFourType
{
    WEAKSELF
    [WYHttpServer getFourBusinessTypeSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            [weakSelf.fourArray addObjectsFromArray:[CJFourBusiness getFourBusinessModelFromJson:response[@"result"]]];
            [weakSelf.tableView reloadData];
        }
        
        
        
    }];
    
}




-(void)loadData
{
    WEAKSELF
    [WYHttpServer getBusinessModuleSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            weakSelf.businessModel = [WYBusinessModule getBusinessModelFromJson:response[@"result"]];
            [weakSelf.tableView reloadData];
            [weakSelf setBanner];
        }
    }];
}
-(void)setBanner
{
    NSMutableArray *imageArray=[[NSMutableArray alloc]init];
    
    if (self.businessModel.slideshow.count) {
        for (WYSlideshow *slidesShow in self.businessModel.slideshow) {
            NSString *imageUrl = [NSString stringWithFormat:@"%@!default",slidesShow.url];
            [imageArray addObject:imageUrl];
        }
        
        
    }
    [self.advView setImageURLStringsGroup:imageArray];
}
-(void)setupUI
{
    [self.view addSubview:self.tableView];
    self.tableView.contentInset = UIEdgeInsetsMake(IMAGE_HEIGHT, 0, 0, 0);
    [self.tableView addSubview:self.advView];
    
    UITextField *textField = [self addSearchTextFiled];
    textField.delegate = self;
    self.textField = textField;
    [self.tableView addSubview:textField];
    textField.frame = CGRectMake(16, -23, kScreenWidth-32, 46);
    UIColor *clr = [UIColor hexStringToColor:@"#A7AFC6" alpha:0.2];
    //self.backgroundColor = clr;
    textField.layer.shadowColor = clr.CGColor;
    //textField.layer.cornerRadius = 5;
    textField.layer.shadowOffset = CGSizeMake(0,0);
    textField.layer.shadowOpacity = 1.0;
    textField.layer.shadowRadius = 8;
    textField.layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, textField.bounds.size.height/3, textField.bounds.size.width, textField.bounds.size.height/3*2)].CGPath;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.tableView.estimatedRowHeight = 100;
    [self.tableView registerNib:[UINib nibWithNibName:@"WYBrandCell" bundle:nil] forCellReuseIdentifier:@"WYBrandCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYCategoryTableViewCell" bundle:nil] forCellReuseIdentifier:@"WYCategoryTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYHotIndustryCell" bundle:nil] forCellReuseIdentifier:@"WYHotIndustryCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYBusinessRecommendCell" bundle:nil] forCellReuseIdentifier:@"WYBusinessRecommendCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYHotIndustryViewCell" bundle:nil] forCellReuseIdentifier:@"WYHotIndustryViewCell"];
   
    
    [self.tableView registerClass:[WYStrictSeletedTableViewCell class] forCellReuseIdentifier:@"WYStrictSeletedTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJTopLineOneCell" bundle:nil] forCellReuseIdentifier:@"CJTopLineOneCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJTopLineThreeCell" bundle:nil] forCellReuseIdentifier:@"CJTopLineThreeCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJTopLineBigCell" bundle:nil] forCellReuseIdentifier:@"CJTopLineBigCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"CJBOSSRecommendCell" bundle:nil] forCellReuseIdentifier:@"CJBOSSRecommendCell"];
    
    
    self.tableView.backgroundColor = [UIColor hexStringToColor:@"#f7f7f7" alpha:1.0];
    
   // self.navigationItem.title = @"商机";
    [self wr_setNavBarBackgroundAlpha:0];
    
    UITextField *navTextField = [self addSearchTextFiled];
    navTextField.delegate = self;
    navTextField.backgroundColor = [UIColor whiteColor];
    UIView *titleView = [[UIView alloc]init];
    self.titleView = titleView;
    [titleView addSubview:navTextField];
    titleView.backgroundColor = [UIColor whiteColor];
    titleView.frame = CGRectMake(16, 0, kScreenWidth-32, 30);
    navTextField.frame = CGRectMake(0, 0, kScreenWidth-32, 30);
    self.titleView.hidden = YES;
    self.navigationItem.titleView = titleView;
    [self wr_setNavBarBackgroundAlpha:0];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    
    NSLog(@"%f",offsetY);
    
    if (offsetY >0) {
//        CGFloat alpha = (offsetY - self.navHeight) / self.navHeight;
        [self wr_setNavBarBackgroundAlpha:1];
        self.titleView.hidden = NO;
    }else{
        self.titleView.hidden = YES;
        [self wr_setNavBarBackgroundAlpha:0];
    
    }
    
    
    
    
}
-(UITextField *)addSearchTextFiled
{
    UITextField *textField = [[UITextField alloc]init];
    textField.placeholder = @"搜索品牌、产品、人脉、资讯";
    //[self.tableView addSubview:textField];
   // textField.frame = CGRectMake(16, -23, kScreenWidth-32, 46);
   // textField.backgroundColor = [UIColor redColor];
    textField.font = [UIFont systemFontOfSize:14];
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.leftView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"search"]];
    textField.backgroundColor = [UIColor whiteColor];
    return textField;
}





-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }
//    if (section==1) {
//        return 1;
//    }
    if (section==1) {
        return self.headLineArray.count;
    }
    if (section==2) {
        return self.recommendArray.count;
    }
//    if (section==2) {
//        return 1;
//    }
    
    return 0;
  //  return self.businessModel.businessOpportunity.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        WYCategoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYCategoryTableViewCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"WYCategoryTableViewCell" owner:nil options:nil].firstObject;
        }
        cell.delegate = self;
        if (self.fourArray.count) {
            [cell setDataArray:self.fourArray];
        }
        if (self.adverArray.count) {
            [cell setModel:self.adverArray[0]];
        }
        
        
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.section==1) {
        CJBOSSHeadLine *bossLine = self.headLineArray[indexPath.row];
        if (bossLine.headlineType.intValue==1) {
            CJTopLineOneCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJTopLineOneCell" forIndexPath:indexPath];
            if (!cell) {
                cell = [[NSBundle mainBundle]loadNibNamed:@"CJTopLineOneCell" owner:nil options:nil].firstObject;
            }
            [cell setBossLine:bossLine];
          //  cell.backgroundColor = [UIColor yellowColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        if (bossLine.headlineType.intValue==2) {
            CJTopLineThreeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJTopLineThreeCell" forIndexPath:indexPath];
            if (!cell) {
                cell = [[NSBundle mainBundle]loadNibNamed:@"CJTopLineThreeCell" owner:nil options:nil].firstObject;
            }
            [cell setBossLine:bossLine];
          //  cell.backgroundColor = [UIColor redColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        if (bossLine.headlineType.intValue==3) {
            CJTopLineBigCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJTopLineBigCell" forIndexPath:indexPath];
            if (!cell) {
                cell = [[NSBundle mainBundle]loadNibNamed:@"CJTopLineBigCell" owner:nil options:nil].firstObject;
            }
            [cell setBossLine:bossLine];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
          //  cell.backgroundColor = [UIColor purpleColor];
            return cell;
        }
        
        
        
        
    }
    if (indexPath.section==2) {
        
        CJBOSSRecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJBOSSRecommendCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[NSBundle mainBundle]loadNibNamed:@"CJBOSSRecommendCell" owner:nil options:nil].firstObject;
        }
        cell.delegate = self;
        CJBOSSRecommend *recommend = self.recommendArray[indexPath.row];
        [cell setRecommend:recommend];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    
   
    
    
    
    
//    WYBusinessRecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYBusinessRecommendCell" forIndexPath:indexPath];
//    WYBusinessOpportunity *bus = self.businessModel.businessOpportunity[indexPath.row];
//    [cell setBusiness:bus];
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return nil;
    
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(void)clickCommissionBtn:(CJBOSSRecommendCell *)cell
{
    
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    CJCommissionController *ccc = [[CJCommissionController alloc]init];
    CJBOSSRecommend *model =self.recommendArray[indexPath.row];
    ccc.businessId = model.opportunityId;
    [self.navigationController pushViewController:ccc animated:YES];
    
}





-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section==1) {
        CJTopLineDetailController *tdc = [[CJTopLineDetailController alloc]init];
         CJBOSSHeadLine *bossLine = self.headLineArray[indexPath.row];
        tdc.navTitle = bossLine.firmSimpleName;
        tdc.topLineID = bossLine.headlineId;
        
        [self.navigationController pushViewController:tdc animated:YES];
    }
    if (indexPath.section==2) {
        CJBOSSRecommend *model =self.recommendArray[indexPath.row];
        CJBrandDetailController *bdc = [[CJBrandDetailController alloc]init];
        
        bdc.businessID = model.opportunityId;
        
        [self.navigationController pushViewController:bdc animated:YES];
    }
    
    
    
  //  [self tableView:tableView didDeselectRowAtIndexPath:indexPath];
//    if (![self isLogin]) {
//        return;
//    }
//
//
//    WYBusinessOpportunity *bus = self.businessModel.businessOpportunity[indexPath.row];
//    WYBusinessDetailController *bdc = [[WYBusinessDetailController alloc]init];
//    bdc.urlString = bus.businessId;
//    bdc.navTitle = bus.businessName;
//
//
//    [self.navigationController pushViewController:bdc animated:YES];
    
}





-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return nil;
    }
    if (section==1) {
        WYSectionView *view = [[WYSectionView alloc]init];
        view.delegate = self;
        view.backgroundColor = [UIColor whiteColor];
        view.textLabel.text = @"BOSS头条";
        view.moreLabel.hidden = YES;
        view.moreButton.hidden = YES;
        view.moreImageView.hidden = YES;
        return view;
    }
    if (section==2) {
        WYSectionView *view = [[WYSectionView alloc]init];
        view.delegate = self;
        view.backgroundColor = [UIColor whiteColor];
        view.textLabel.text = @"BOSS推荐";
        view.moreLabel.hidden = YES;
        view.moreButton.hidden = YES;
        view.moreImageView.hidden = YES;
        return view;
    }
//    if (section==3) {
//        WYSectionView *view = [[WYSectionView alloc]init];
//        view.delegate = self;
//        view.backgroundColor = [UIColor whiteColor];
//        view.textLabel.text = @"BOSS推荐";
//        view.moreLabel.hidden = YES;
//        view.moreButton.hidden = YES;
//        view.moreImageView.hidden = YES;
//        return view;
//    }
//    if (section==4) {
//        WYSectionView *view = [[WYSectionView alloc]init];
//        view.delegate = self;
//        view.backgroundColor = [UIColor whiteColor];
//        view.textLabel.text = @"BOSS推荐";
//        view.moreLabel.hidden = YES;
//        view.moreButton.hidden = YES;
//        view.moreImageView.hidden = YES;
//        return view;
//    }
    
    
    
    return nil;
}
-(void)clickMoreButtonAction:(UIButton *)btn
{
    if (![self isLogin]) {
        return;
    }
    WYBrandController *bvc = [[WYBrandController alloc]init];
    [self.navigationController pushViewController:bvc animated:YES];
}
-(void)clickmore:(UIButton *)btn
{
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return 0.00000001;
    }
    return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0000001;
}
#pragma  mark - WYCategoryCellDelegate
-(void)didSelectCollectionViewcellWithIndex:(NSIndexPath *)index WtihID:(NSString *)ID
{
    if (![self isLogin]) {
        return;
    }
    
//    CJBusinessTypeController *btc = [[CJBusinessTypeController alloc]init];
//
//    [self.navigationController pushViewController:btc animated:YES];
    CJFourBusiness *business = self.fourArray[index.row];
    if (business.sortId ==1) {
        CJBrandJoinController *bjc = [[CJBrandJoinController alloc]init];
        bjc.sortId = business.sortId;
        [self.navigationController pushViewController:bjc animated:YES];
    }
    if (business.sortId == 2) {
        CJChannelController *ccc = [[CJChannelController alloc]init];
        ccc.sortId = business.sortId;
        [self.navigationController pushViewController:ccc animated:YES];
    }
    if (business.sortId ==3) {
        CJBOSSPersonController *bpc = [[CJBOSSPersonController alloc]init];
        [self.navigationController pushViewController:bpc animated:YES];
    }
    if (business.sortId==4) {
        CJTopLineController *tlc = [[CJTopLineController alloc]init];
        tlc.sortId = business.sortId;
        
        [self.navigationController pushViewController:tlc animated:YES];
    }
    
    
    
//    WYBusinessType *businessType =self.businessModel.businessType[index.row];
//    WYBrandController *bvc = [[WYBrandController alloc]init];
//    bvc.typeID = ID;
//    bvc.navTitle = businessType.name;
//    [self.navigationController pushViewController:bvc animated:YES];
//    WYFoodController *foodVc = [[WYFoodController alloc]init];
//    [self.navigationController pushViewController:foodVc animated:YES];
}

-(void)didAdverImageViewWithModel:(CJBrandAdvertising *)model
{
    CJBrandDetailController *bdc = [[CJBrandDetailController alloc]init];
    
    bdc.businessID = model.opportunityId;
    
    [self.navigationController pushViewController:bdc animated:YES];
}


-(void)didCellImageViewWithModel:(id)model
{
    if (![self isLogin]) {
        return;
    }
    if ([model isKindOfClass:[WYHotSector class]]) {
        WYHotSector *HotSector =model;
        
        WYBrandController *bvc = [[WYBrandController alloc]init];
        bvc.typeID = HotSector.id;
        bvc.navTitle = HotSector.name;
        [self.navigationController pushViewController:bvc animated:YES];
    }
    if ([model isKindOfClass:[WYBrandZone class]]) {
        WYBrandZone *brandZone = model;
        
        WYBusinessDetailController *bvc = [[WYBusinessDetailController alloc]init];
        bvc.urlString = brandZone.businessId;
        bvc.navTitle = brandZone.businessName;
        [self.navigationController pushViewController:bvc animated:YES];
        
    }
    
    
    
    
    
    
}


-(void)didChangeHeight:(WYCategoryTableViewCell *)cell
{
    [self.tableView reloadData];
}
#pragma WYBrandCellDelegate
-(void)clickImageViewWithTag:(NSUInteger)tag
{
    if (self.businessModel.brandZone.count) {
        WYBusinessDetailController *bdc = [[WYBusinessDetailController alloc]init];
        WYBrandZone *zone1 = self.businessModel.brandZone[tag-1];
        bdc.urlString = zone1.businessId;
        bdc.navTitle = zone1.businessName;
        [self.navigationController pushViewController:bdc animated:YES];
        
    }
   
    
    
}
/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (![self isLogin]) {
        return;
    }
    WYSlideshow *slideshow = self.bannerArray[index];
//    WYBusinessDetailController *bdc = [[WYBusinessDetailController alloc]init];
//    bdc.urlString = slideshow.businessId;
//    bdc.navTitle = slideshow.businessName;
//    [self.navigationController pushViewController:bdc animated:YES];
    
    CJBrandDetailController *bdc = [[CJBrandDetailController alloc]init];
    
    bdc.businessID = slideshow.opportunityId;
    
    [self.navigationController pushViewController:bdc animated:YES];
    
    
    
    NSLog(@"点击了某张图片");
    
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index
{
    
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight-self.tabHeight);
        _tableView = [[UITableView alloc] initWithFrame:frame
                                                  style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    }
    return _tableView;
}
- (SDCycleScrollView *)advView
{
    if (_advView == nil) {
        _advView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, -IMAGE_HEIGHT, kScreenWidth, IMAGE_HEIGHT) imageNamesGroup:nil];
        //_advView.pageDotColor = [UIColor grayColor];
        _advView.pageDotImage = [UIImage imageNamed:@"icon_cycire"];
        _advView.currentPageDotImage = [UIImage imageNamed:@"icon_cycire_select"];
        _advView.autoScrollTimeInterval = 2;
//        _advView.currentPageDotColor = [UIColor whiteColor];
        _advView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
       // _advView.backgroundColor = [UIColor redColor];
        _advView.delegate = self;
    }
    return _advView;
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //[self wr_setNavBarBackgroundAlpha:1];
}


-(BOOL)isLogin
{
    NSString *token =[WYStoreModule currentToken];
    if (token.length) {
        return YES;
    }else{
        WYLoginController *loginVc = [[WYLoginController alloc] initWithNibName:@"WYLoginController" bundle:nil];
        WYBaseNavigationController *nav = [[WYBaseNavigationController alloc]initWithRootViewController:loginVc];
        [self presentViewController:nav animated:YES completion:nil];
        return NO;
    }
    
}







@end
